#include "../header/picasa_test.h"

#include <QMap>
#include <QString>
#include <QSignalSpy>

void TestPicasa::initTestCase()
{
	pikaska = new Picasa;
	postImage = new PostImage;
}

void TestPicasa::myFirstTest()
{
	//QVERIFY(1 == 2);
}

void TestPicasa::BuildPostDataTest()
{
	QMap<QString, QString> map;
	map["test"] = "test1";
	map["test_a"] = "test b";
	QString response( pikaska->BuildPostData(map) );
	QString needed= "test=test1&test_a=test%20b";
	QCOMPARE(response, needed);
}

void TestPicasa::ParseAuthResponseTest()
{
	QString response = "SID=ABC-9-AA_XT=ABDC=8\n \
	LID=DQAAAHwAAAAr0mBsw7z1WdlVnvgi0XDXJ0jkqHW2LRBmJ_fdvbv9AgkxHCtxuUFAt9ychS-4eRnpw03Ntqe1YloipiRE4wUP-WavcbX1TMOdq8LF_HQhBEZU6KtjD5QwNyZphh6JXMHzqRr7tOq7Dmc-atPiI6p9Fm5gHkzAHebprMk0Co8Tww\n \
	Auth=Captcha?gg=3\n";
	
	QMap<QString, QString> map;
	pikaska->ParseAuthResponse( response, map );
	QCOMPARE( map["SID"], QString("ABC-9-AA_XT=ABDC=8") );
	QCOMPARE( map["Auth"], QString("Captcha?gg=3") );
}

void TestPicasa::AllWithImage()
{
	//pikaska->PostImage("AlbumName", "image");
}

void TestPicasa::TestDirector()
{
	//pikaska->Director("./", "Test1");
}
void TestPicasa::TestHoleAuth()
{
	///*
	qRegisterMetaType<StringMap>("StringMap");
	QSignalSpy Spy( pikaska, SIGNAL( siAuth(const StringMap&) ) );
	
	int CurrentCount = Spy.count();
	pikaska->Auth("ivan.shmidt", "killmelater");

	while( Spy.count() == CurrentCount )
		QTest::qWait(250);
	
	QCOMPARE(Spy.count(), CurrentCount + 1);
	qDebug() << qvariant_cast<StringMap>(Spy.at(0).at(0));// ura blin!!!
	//*/
}

void TestPicasa::TestGetExistingAlbums()
{
/*
	qRegisterMetaType<StringVector>("StringVector");
	QSignalSpy Spy( pikaska, SIGNAL( siGetExistingAlbums(const StringVector&) ) );
	
	int CurrentCount = Spy.count();
	pikaska->GetExistingAlbums("ivan.shmidt");

	while( Spy.count() == CurrentCount )
		QTest::qWait(250);
	
	QCOMPARE(Spy.count(), CurrentCount + 1);
	qDebug() << qvariant_cast<StringVector>(Spy.at(0).at(0));// ura blin!!!
*/
}

void TestPicasa::PostImageTest()
{
	/*postImage->Add( 1 );
	QByteArray byteArray("abc");
	postImage->buffers[0] = new QBuffer(&byteArray);
	QString str( postImage->GetBufferById(1)->data() );

	QCOMPARE(QString("abc"), str);
*/
}

void TestPicasa::cleanupTestCase()
{
	delete pikaska;
	delete postImage;
}

QTEST_MAIN(TestPicasa)

